import { randomBytes } from '@stablelib/random'
import { generateKeyPairFromSeed, marshalPrivateKey } from '@libp2p/crypto/keys'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'

export function generateSeed() {
    return randomBytes(32);
}

export function seedToHex(seed) {
    return Buffer.from(seed).toString('hex');
}

export function seedHexToSeed(seedHex) {
    return new Uint8Array(Buffer.from(seedHex, 'hex'));
}

export const seedHexToPriveKey = async (seedHex) => {
    const seed = seedHexToSeed(seedHex)
    const key = await generateKeyPairFromSeed('Ed25519', seed)
    return uint8ArrayToString(marshalPrivateKey(key), 'base64pad')
}

export const DEFAULT_HEX = '41e91ef82a04c73a6d5f1d7f947137a900e3b82d871d07a455932d69cf26ed14'
